home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example7.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  162 lines

  1. /* Example7                                                           */
  2. /* This program explains how to use the IDCMP flags: DISKINSERTED and */
  3. /* DISKREMOVED.                                                       */
  4.  
  5.  
  6.  
  7. #include <intuition/intuition.h>
  8.  
  9.  
  10.  
  11. struct IntuitionBase *IntuitionBase;
  12.  
  13.  
  14.  
  15. /* Declare a pointer to a Window structure: */ 
  16. struct Window *my_window;
  17.  
  18. /* Declare and initialize your NewWindow structure: */
  19. struct NewWindow my_new_window=
  20. {
  21.   50,             /* LeftEdge    x position of the window. */
  22.   25,             /* TopEdge     y positio of the window. */
  23.   320,            /* Width       320 pixels wide. */
  24.   100,            /* Height      100 lines high. */
  25.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  26.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  27.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  28.                   /*             selects the Close window gad.           */
  29.  
  30.   DISKINSERTED|   /*             We will also recieve a message whenever */
  31.   DISKREMOVED,    /*             a disk is inserted or removed.          */
  32.  
  33.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  34.   WINDOWCLOSE|    /*             Close Gadget. */
  35.   WINDOWDRAG|     /*             Drag gadget. */
  36.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  37.   WINDOWSIZING|   /*             Sizing Gadget. */
  38.   ACTIVATE,       /*             The window should be Active when opened. */
  39.   NULL,           /* FirstGadget No gadgets connected to this window. */
  40.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  41.   "TOUCH MY DISKS",/* Title      Title of the window. */
  42.   NULL,           /* Screen      Connected to the Workbench Screen. */
  43.   NULL,           /* BitMap      No Custom BitMap. */
  44.   100,            /* MinWidth    We will not allow the window to become */
  45.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  46.   400,            /* MaxWidth    than 400 x 200. */
  47.   200,            /* MaxHeight */
  48.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  49. };
  50.  
  51.  
  52.  
  53. /**************************************************************************/
  54. /* Extra information:                                                     */
  55. /* The IDCMP messages DISKINSERTED and DISKREMOVED can not be "swollowed" */
  56. /* by a program. All applications will hear about it if they want. This   */
  57. /* is the opposite of other IDCMP flags which will be "swollowed" by the  */
  58. /* active window's program.                                               */
  59. /**************************************************************************/
  60.  
  61.  
  62.  
  63. main()
  64. {
  65.   /* Boolean variable used for the while loop: */
  66.   BOOL close_me;
  67.  
  68.   ULONG class; /* IDCMP flag. */
  69.  
  70.   /* Pointer to an IntuiMessage structure: */
  71.   struct IntuiMessage *my_message;
  72.  
  73.  
  74.  
  75.   /* Before we can use Intuition we need to open the Intuition Library: */
  76.   IntuitionBase = (struct IntuitionBase *)
  77.     OpenLibrary( "intuition.library", 0 );
  78.   
  79.   if( IntuitionBase == NULL )
  80.     exit(); /* Could NOT open the Intuition Library! */
  81.  
  82.  
  83.  
  84.   /* We will now try to open the window: */
  85.   my_window = (struct Window *) OpenWindow( &my_new_window );
  86.   
  87.   /* Have we opened the window succesfully? */
  88.   if(my_window == NULL)
  89.   {
  90.     /* Could NOT open the Window! */
  91.     
  92.     /* Close the Intuition Library since we have opened it: */
  93.     CloseLibrary( IntuitionBase );
  94.  
  95.     exit();  
  96.   }
  97.  
  98.  
  99.  
  100.   /* We have opened the window, and everything seems to be OK. */
  101.  
  102.   printf("Insert or remove a disk!\n\n");
  103.  
  104.  
  105.  
  106.   close_me = FALSE;
  107.  
  108.   /* Stay in the while loop until the user has selected the Close window */
  109.   /* gadget: */
  110.   while( close_me == FALSE )
  111.   {
  112.     /* Wait until we have recieved a message: */
  113.     Wait( 1 << my_window->UserPort->mp_SigBit );
  114.  
  115.  
  116.     /* As long as we can collect messages successfully we stay in the */
  117.     /* while-loop: */
  118.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  119.     {
  120.       /* After we have successfully collected the message we can read */
  121.       /* it, and save any important values which we maybe want to check */
  122.       /* later: */
  123.       class = my_message->Class;         /* IDCMP flag. */
  124.  
  125.  
  126.       /* After we have read it we reply as fast as possible: */
  127.       /* REMEMBER! Do never try to read a message after you have replied! */
  128.       /* (Some other process has maybe changed it.) */
  129.       ReplyMsg( my_message );
  130.  
  131.  
  132.       /* Check which IDCMP flag was sent: */
  133.       switch( class )
  134.       {
  135.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  136.                close_me=TRUE;
  137.                break;
  138.  
  139.         case DISKINSERTED:   /* The user inserted a disk in a drive. */
  140.                printf("Disk inserted!\n");
  141.                break;
  142.  
  143.         case DISKREMOVED:    /* The user removed a disk from a drive. */
  144.                printf("Disk removed!\n");
  145.                break;
  146.       }
  147.     }
  148.   }
  149.  
  150.  
  151.  
  152.   /* Close the window: */
  153.   CloseWindow( my_window );
  154.  
  155.  
  156.  
  157.   /* Close the Intuition Library: */
  158.   CloseLibrary( IntuitionBase );
  159.   
  160.   /* THE END */
  161. }
  162.